home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: news.inap.net!news1!ind-006-236-238
- From: dlmiller@iquest.net (Doug Miller)
- Subject: Re: Why does my program do this?
- X-Nntp-Posting-Host: ind-006-236-238.iquest.net
- Message-ID: <Dp8Lpn.7EB@iquest.net>
- Sender: news@iquest.net (News Admin)
- Organization: IQuest Network Services
- X-Newsreader: News Xpress Version 1.0 Beta #2.1
- References: <4jnln2$95j@dfw-ixnews3.ix.netcom.com>
- Date: Tue, 2 Apr 1996 13:36:59 GMT
-
- ishky@ix.netcom.com(Andrew Heiz ) wrote:
- >Hi again,
- >
- >There have been so many helpful readers out there here is another
- >question for you.
- >
- >I've declared an 2 dimentional array:
- >
- >char scores[STUDENT][5];
- >
- >I am entering the scores in 2 for loops like this:
- >
- > for (i=0; i <= students-1; i=i+1)
- > {
- > for (j=0; j <= tests-1; j=j+1)
- > {
- > gets(&scores[i][j];
- > }
- > }
- >
- >I print out the scores in the same type of loop structure:
- >
- > for (i=0; i <= students-1; i=i+1)
- > {
- > printf("Scores for student %d",i+1);
- > for (j=0; j <= tests-1; j=j+1)
- > {
- > printf("\tGrade %d: %s",j+1,scores[i][j]);
- > }
- > }
- >
- >I am getting (if you don't already know this):
- >
- > Scores for student 1: Grade 1: 999991 Grade 2: 99991 Grade
- >3: 9991 Grade 4: 991 Grade 5: 91
- >
- >Is my data being mangled some how in the data entry? I've tried just
- >printing out 1 array element or not using the loop and naming each
- >element but nothing seems to work.
- >
- >If you can explain why this is happening and how to fix it my computer
- >would be greatful. I've been making some awful threats at it today. It
- >must be something simple I'm overlooking.
- >
- >Thanks again if you have helped me in the past and with this question.
- >
- >Please post or e-mail your response.
- >
- >Happy coding,
- >Andy
- >e-mail ishky@ix.netcom.com
-
- Is there a particular reason you have declared scores as char? Perhaps changing the declaration
- to a numeric type would help. :-)
-
-